package org.myOrg.spetrum.SpecificAlogrithm;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import org.myOrg.spetrum.combination.Tuple;
import org.myOrg.spetrum.spectrumStruct.SpectrumFactory;
import org.myOrg.spetrum.spectrumStruct.SpetrumAnalyseBase;
import org.myOrg.spetrum.testObject.TestSuite;
import org.myOrg.spetrum.testRun.TestRun;

public class SpectrumAnalyseWidthFirst extends SpetrumAnalyseBase {

	public SpectrumAnalyseWidthFirst(TestRun run,int[] param, TestSuite wrongTestCases,
			TestSuite rightTestCases) {
		super(run,param, wrongTestCases, rightTestCases);
		this.id = SpectrumFactory.WIDTHFIRST;
	}

	public SpectrumAnalyseWidthFirst() {
		super();
		this.id = SpectrumFactory.WIDTHFIRST;
	}

	@Override
	public void init() {

		List<Tuple> tuples = setUp.getCandidateHeadTuple();

		double widthValue = getTupleManager().size() + 1;

		widthSerchSetSuspicion(tuples, widthValue);
	}

	public void widthSerchSetSuspicion(List<Tuple> tuples, double value) {
		Iterator<Tuple> itrTuple = tuples.iterator();
		HashSet<Tuple> childs = new HashSet<Tuple>();
		while (itrTuple.hasNext()) {
			Tuple tuple = itrTuple.next();
			this.getTupleManager().getTupleAnalyseStructByTuple(tuple)
					.setSuspicion(value--);
			childs.addAll(tuple.getChildTuples());
		}
		if (childs.size() > 0)
			widthSerchSetSuspicion(new ArrayList<Tuple>(childs), value);
		else
			return;
	}
}
